package com.ruima.study.jdk21.demo1;

public class Demo5Match {
    public static void main(String[] args) {
        Demo5Match demo = new Demo5Match();

        demo.matchByJDK8(22);
        demo.matchByJDK17(23);

        demo.matchByJDK8("mdk");
        demo.matchByJDK17("mdk");
    }

    /**
     * 旧式写法
     *
     * @param value
     */
    public void matchByJDK8(Object value) {
        if (value instanceof String) {
            String v = (String)value;
            System.out.println("遇到一个String类型" + v.toUpperCase());
        } else if (value instanceof Integer) {
            Integer v = (Integer)value;
            System.out.println("遇到一个整型类型" + v.longValue());
        }
    }

    /**
     * 17的写法
     *
     * @param value
     */
    public void matchByJDK17(Object value) {
        if (value instanceof String v) {
            System.out.println("遇到一个String类型" + v.toUpperCase());
        } else if (value instanceof Integer v) {
            System.out.println("遇到一个整型类型" + v.longValue());
        }
    }


}
